package disenioPantallas.elementos;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.UIManager;
import java.awt.Dimension;
import javax.swing.border.Border;

import java.awt.SystemColor;
import java.util.Vector;

public abstract class panelGeneral  extends JPanel implements iFuncionalidad{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Vector<Object> obligatorios= new Vector<Object>();
	private Border redLine=BorderFactory.createLineBorder(Color.red);
	private Border text;
	private Border combo;


	public panelGeneral(){
		super();
		setPreferredSize(new Dimension(800, 1500));
		setBackground(SystemColor.activeCaptionBorder);
		setOpaque(true);
		setMinimumSize(new Dimension(800, 600));
		
		
		text= (new JTextField()).getBorder();
		combo=(new JComboBox<String>()).getBorder();


		try
		{
			JFrame.setDefaultLookAndFeelDecorated(true);
			JDialog.setDefaultLookAndFeelDecorated(true);
			UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
		}
		catch (Exception e)
		{
		 	e.printStackTrace();
		}

		
		
	}
	

	

	 public void paintComponent (Graphics g)
	    { 
	((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.6f)); // draw transparent background
	     super.paintComponent(g);
	    ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1.0f)); // turn on opacity
	    }
	 
	 
		// Devuelve true si estan todos completos.
		// Devuelve true si estan todos completos.
		public boolean camposObligatorios(Vector<Object> componentes){
			boolean flag= true;
			if(!componentes.isEmpty()){
				for(int i=0;i<componentes.size();i++){
					Object elemento=componentes.get(i);
					
					try {
						if(((JTextField) elemento).getText().equals("")){
							((JTextField) elemento).setBorder(redLine);
							flag=false;
						}else ((JTextField) elemento).setBorder(text);
						} catch (Exception e) {;}

					try {
						if(((JTextArea) elemento).getText().equals("")){
							((JTextArea)elemento).setBorder(redLine);
							flag=false;
						}else ((JTextArea) elemento).setBorder(text);
						} catch (Exception e) {;}

					try {
						if(((JComboBox<String>) elemento).getSelectedItem().equals("")){
							((JComboBox<String>)elemento).setBorder(redLine);
							flag=false;
						}else ((JComboBox<String>) elemento).setBorder(combo);
						} catch (Exception e) {;}
					
				}
			}
			return flag;
			
		}

		
		public Vector<Object> getObligatorios() {
			return obligatorios;
		}

		public void setObligatorios(Vector<Object> obligatorios) {
			this.obligatorios = obligatorios;
		}


}
